package com.pro.controller;

import com.pro.mapper.JsApplicantMapper;
import com.pro.pojo.JsAuditLog;
import com.pro.pojo.JsRole;
import com.pro.pojo.JsonData;
import com.pro.service.JsApplicantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * ClassName:JsApplicantController
 * Package:com.pro.controller
 * Description:
 *
 * @Date:2022/1/26 21:04
 * @Author: XJR
 */
@RequestMapping("/JsApplicant")
@RestController
public class JsApplicantController {

    @Autowired
    private JsApplicantService service;

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/26
     * @Content:查看创作者申请列表
     */
    @RequestMapping("/selectJsApplicant")
    public JsonData selectJsApplicant(String roleName, String applyDate,String result, Integer limit, Integer page){
        List<JsRole> jsRoles = service.selectJsApplicant(roleName, applyDate, result,limit, page);
        Integer count = service.countJsApplicant(roleName, applyDate,result);
        return jsRoles!=null?JsonData.buildSuccess(jsRoles,count):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/26
     * @Content:计算创作者总数
     */
    @RequestMapping("/countJsApplicant")
    public Integer countJsApplicant(String roleName,String applyDate,String result){
        Integer integer = service.countJsApplicant(roleName, applyDate,result);
        return integer;
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/28
     * @Content:审核申请
     */
    @RequestMapping("/aditApplicantStatus")
    public JsonData aditApplicantStatus(JsRole jsRole){
        String result;
        Boolean updaBoolean = service.aditApplicantStatus(jsRole);
        if(jsRole.getResult().equals(2)){
            result="2";
        }else{
            result="1`";
        }
        JsAuditLog jsAuditLog = new JsAuditLog();
        jsAuditLog.setTableName("js_apply_record");
        jsAuditLog.setType(result);
        jsAuditLog.setUserId(jsRole.getImplementId());
        jsAuditLog.setCreateDatee(jsRole.getImplementDatee());
        jsAuditLog.setRemark(jsRole.getRemarks());
        jsAuditLog.setAduitLogType(4);
        jsAuditLog.setMainId(jsRole.getId());
        jsAuditLog.setAduitId(jsRole.getId());
        Boolean addBoolean = service.addJsAuditLog(jsAuditLog);
        return updaBoolean!=false&&addBoolean!=false?JsonData.buildSuccess(updaBoolean):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/28
     * @Content:通过id查看详情
     */
    @RequestMapping("/selectApplicantById")
    public JsonData selectApplicantById(Integer id){
        JsRole jsRole = service.selectApplicantById(id);
        return jsRole!=null?JsonData.buildSuccess(jsRole):JsonData.buildError("服务器发生错误");
    };

    /**
     * @Description:
     * @Author: XJR
     * @Date: 2022/1/30
     * @Content:查看审核日志
     */
    @RequestMapping("/selectJsAuditLog")
    public JsonData selectJsAuditLog(String roleName,String createDate,String type,Integer limit,Integer page){
        List<JsRole> jsRoles = service.selectJsAuditLog(roleName, createDate, type, limit, page);
        Integer count = service.countJsAuditLog(roleName, createDate, type);
        return jsRoles!=null?JsonData.buildSuccess(jsRoles,count):JsonData.buildError("服务器发生错误");
    };

}
